<template>
  <div class="common-layout">
    <el-container>
      <el-header height="100%">
        <HeaderView />
      </el-header>
      <el-main height="100%" style="background-color: #F5F5F5;">
        <div class="attractions-box">
          <div class="recommend-section">
            <div class="recommend-grid">
              <div v-for="attractionVo in attractions" :key="attractionVo.attractions.attractionId"
                class="recommend-card">
                <router-link
                  :to="{ name: 'detail', params: { type: 'attraction', id: attractionVo.attractions.attractionId } }">
                  <img :src="attractionVo.list[0].url" :alt="attractionVo.attractions.name">
                  <div class="card-content">
                    <h3>{{ attractionVo.attractions.name }}</h3>
                    <p>{{ attractionVo.attractions.description }}</p>
                  </div>
                </router-link>
              </div>
            </div>
          </div>


        </div>
      </el-main>
      <el-footer height="100%">
        <FooterView />
      </el-footer>
    </el-container>
  </div>
</template>

<script>
import HeaderView from '@/view/HeaderView.vue';
import FooterView from '@/view/FooterView.vue';
import req from '@/utils/request';

export default {
  name: 'AttractionsView',
  components: {
    HeaderView,
    FooterView
  },
  data() {
    return {
      attractions: []
    }
  },
  mounted() {
    this.getAttractions();
  },
  methods: {
    getAttractions() {
      req.get("/attractions/all").then(res => {
        this.attractions = res.data;
        // console.log(res.data);
        
      });
    }
  }
}
</script>

<style scoped>
a{
  text-decoration: none;
}
.attractions-box {
  width: 1200px;
  margin: 20px auto;
  background-color: white;
  min-height: 600px;
  padding-top: 52px;
  margin-top: 100px;
}

.attractions-container {
  display: flex;
  flex-wrap: wrap;
  /* 允许换行 */
  justify-content: space-between;
  /* 在行之间留出空间 */
}

.attraction-card {
  flex: 0 1 calc(33.33% - 20px);
  /* 每个卡片占据三分之一的宽度，减去间距 */
  margin-bottom: 20px;
  /* 卡片之间的垂直间距 */
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s;
  /* 添加过渡效果 */
}

.attraction-card:hover {
  transform: scale(1.05);
  /* 鼠标悬停时放大 */
}

.attraction-image {
  width: 100%;
  height: auto;
  border-radius: 8px;
}

/* 推荐区域样式 */
.recommend-section {
  padding: 40px 0;
  /* 增加上下间距 */
}

.recommend-section:not(:last-child) {
  margin-bottom: 20px;
  /* 两个推荐区域之间的间距 */
}

.recommend-section h2 {
  color: #333;
  margin-bottom: 30px;
  font-size: 28px;
  text-align: center;
  position: relative;
}

.recommend-section h2::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 50px;
  height: 3px;
  background-color: #B01F24;
}

.recommend-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  /* 改为3列布局 */
  gap: 30px;
  padding: 0 40px;
  max-width: 1200px;
  margin: 0 auto;
}

.recommend-card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.recommend-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.recommend-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.card-content {
  padding: 15px;
}

.card-content h3 {
  margin: 0 0 10px;
  font-size: 18px;
  color: #333;
}

.card-content p {
  margin: 0;
  font-size: 14px;
  color: #666;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
</style>